#pragma once
// 提供计算服务
#include "Protocol.hpp"
class Cal
{
public:
    Cal() {}
    ~Cal() {}
    Response Exeute(Request &req)
    {
        Response rep(0, 0);
        switch (req.Oper())
        {
        case '+':
            rep.SetResult(req.X() + req.Y());
            break;
        case '-':
            rep.SetResult(req.X() - req.Y());
            break;
        case '*':
            rep.SetResult(req.X() * req.Y());
            break;
        case '/':
            if (req.Y() == 0)
                rep.SetCode(1);
            else
                rep.SetResult(req.X() / req.Y());
            break;
        case '%':
            if (req.Y() == 0)
                rep.SetCode(2);
            else
                rep.SetResult(req.X() % req.Y());
            break;
        default:rep.SetCode(3);
            break;
        }
        return rep;
    }
};